<?php

require_once("configure.php");

$user = $_POST["user"];
$name = $_POST["category"];

$MySqlLinkId = mysql_connect(DBHost, DBUser, DBPwd);
if($MySqlLinkId == FALSE)
{
	echo("({ErrCode:1, ErrMsg:'链接数据库失败！'})");
	exit();
}

if(FALSE == mysql_select_db(DB, $MySqlLinkId))
{
	echo("({ErrCode:2, ErrMsg:'".json_encode(mysql_error($MySqlLinkId))."'})");
	mysql_close($MySqlLinkId);
	exit();
}

if(FALSE == mysql_query("INSERT INTO BillCategory(Name, AccountName) VALUES('".mysql_real_escape_string($name)."', '".mysql_real_escape_string($user)."')", $MySqlLinkId))
{
	echo("({ErrCode:3, ErrMsg:'".json_encode(mysql_error($MySqlLinkId))."'})");
	mysql_close($MySqlLinkId);
	exit();
}
else
{
	echo("({ErrCode:0, ErrMsg:'', Category:{Id:".json_encode(mysql_insert_id()).", Name:".json_encode($name)."}})");
	mysql_close($MySqlLinkId);
	exit();
}

?>